﻿using System;
using UnityEngine;

namespace Vosvek.ProjectRogue
{

    [Serializable]
    public class Mover
    {
        public static bool UseSmoothMovement;

        public readonly Actor Parent;

        public Mover(Actor parent)
        {
            this.Parent = parent;
        }

        public bool CanMove(Vector2 direction)
        {
            // TODO: Implement.
            throw new NotImplementedException();
        }

        public bool TryMove(Vector2 direction)
        {
            // Define destination.
            Vector3 destination = Parent.transform.position + (Vector3)direction;

            // Check the destination for a hit.
            RaycastHit2D hit = Physics2D.Raycast(destination, Vector2.zero);

            // If there is a collider at the destination, use the object.
            if (hit.collider != null)
            {
                //hit.collider.gameObject.SendMessage("Use", Parent, SendMessageOptions.DontRequireReceiver);
                return false;
            }
            // Otherwise, move into the position.
            else
            {
                Parent.transform.position = destination;
                return true;
            }
        }
    }

}
